using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using VoteMeDefine;
using System.IO;
using System.Reflection;
using System.Collections;


namespace VoteMe
{
    static class Program
    {

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]

        static void Main()
        {
            initAllPublicVariable();
            Application.Run(new FrmLogon());
            
        }

        private static void initAllPublicVariable()
        {
            VariableDefine.appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            VariableDefine.connString = @"DataSource= " + VariableDefine.appPath + @"\VoteMeDB.sdf";
            VariableDefine.meConn = new SqlCeConnection(VariableDefine.connString);
            VariableDefine.meCmd = VariableDefine.meConn.CreateCommand();
            VariableDefine.iniPath = VariableDefine.appPath + @"\conf.ini";
            //read pictures location from ini file;
            //StreamReader srIni = File.OpenText(VariableDefine.iniPath);
            //VariableDefine.meConn.Open();
            //VariableDefine.meCmd.CommandText = "SELECT Value FROM conf WHERE Variable='PictureLocation'";
            //SqlCeResultSet meRs = VariableDefine.meCmd.ExecuteResultSet(VariableDefine.meRSOptions);
            //while (meRs.Read())
            //{
            //    VariableDefine.picturePath  = meRs.GetString(0);
            //}
            using (StreamReader sr = File.OpenText(VariableDefine.iniPath))
            {
                while (!sr.EndOfStream)
                {
                    string strTmp = sr.ReadLine();
                    if (strTmp.IndexOf("[Pictures Location]") == 0)
                    {
                        VariableDefine.picturePath = strTmp.Split('=')[1].ToString();
                    }
                    if (strTmp.IndexOf("[Groups]") == 0)
                    {
                        VariableDefine.groups = strTmp.Split('=')[1].ToString();
                    }
                    if (strTmp.IndexOf("[Rates]") == 0)
                    {
                        VariableDefine.rates = strTmp.Split('=')[1].ToString();
                    }

                }
                sr.Close();
            }
            VariableDefine.alPicFileName = new ArrayList();
            
        }
        
    }
}